<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
    </h:head>
    <h:body>
        <p:layout fullPage="true">
            <!-- BANNER -->
            <p:layoutUnit position="north" id="menu">
                <ui:include src="../basic/banner.xhtml" />
            </p:layoutUnit>
            <!-- MENU -->
            <p:layoutUnit position="west">
                <ui:include src="../basic/menu.xhtml" />
            </p:layoutUnit>
            <!-- CONTENT -->
            <h:form>
                <p:layoutUnit position="center">
                    <p:messages />
                    <p:commandButton value="Add Patient" onclick="dlgAddPatient.show()" />

                    <p:dataTable var="patient" value="#{patientManagerBean.patientList}"
                                 paginator="true" rows="10">

                        <f:facet name="header">Patient List</f:facet>
                        <p:column headerText="Firstname">#{patient.firstName}</p:column>
                        <p:column headerText="LastName">#{patient.lastName}</p:column>
                        <p:column headerText="Priority">#{patient.priority}</p:column>
                        <p:column headerText="Address">#{patient.address}</p:column>
                        <p:column headerText="Modify" style="text-align: center">
                            <p:commandButton update=":modalUpdatePatient"
                                             oncomplete="dlgUpdatePatient.show()" icon="ui-icon-document">
                                <f:setPropertyActionListener value="#{patient}"
                                                             target="#{patientManagerBean.selectedPatient}" />
                            </p:commandButton>
                        </p:column>
                        <p:column headerText="Delete" style="text-align: center">
                            <p:commandButton update=":modalDeletePatient"
                                             oncomplete="dlgDeletePatient.show()" icon="ui-icon-trash">
                                <f:setPropertyActionListener value="#{patient}"
                                                             target="#{patientManagerBean.selectedPatient}" />
                            </p:commandButton>
                        </p:column>
                    </p:dataTable>
                </p:layoutUnit>
            </h:form>
        </p:layout>

        <!-- Add Patient Modal -->
        <p:dialog id="modalAddPatient" header="Patient Information"
                  widgetVar="dlgAddPatient" modal="true">
            <h:form>
                <p:tabView orientation="left">
                    <p:tab title="Patient">
                        <p:panelGrid columns="2">
                            <h:outputText id="firstname" value="First name (*) :" />
                            <p:inputText value="#{patientManagerBean.newPatient.firstName}" />

                            <h:outputText id="lastname" value="Last name (*) :" />
                            <p:inputText value="#{patientManagerBean.newPatient.lastName}" />

                            <h:outputText id="birthday" value="Birthday :" />
                            <p:inputText value="#{patientManagerBean.newPatient.birthday}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </p:inputText>

                            <h:outputText id="ssid" value="Ssid :" />
                            <p:inputText value="#{patientManagerBean.newPatient.ssid}" />

                            <h:outputText id="phone" value="Phone (*) :" />
                            <p:inputText value="#{patientManagerBean.newPatient.phone}" />

                            <h:outputText id="address" value="Address (*) :" />
                            <p:inputText value="#{patientManagerBean.newPatient.address}" />

                            <h:outputText id="priority" value="Priority :" />
                            <p:inputText value="#{patientManagerBean.newPatient.priority}" />
                        </p:panelGrid>
                    </p:tab>
                    <p:tab title="Professional">
                        <p:panelGrid columns="2">
                            <h:outputText id="medecin" value="Medecin :" />
                            <p:selectOneMenu value="#{patientManagerBean.newPatient.medecin}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="medecinConverter" />
                                <f:selectItems value="#{medecinManagerBean.medecinList}" />
                            </p:selectOneMenu>

                            <h:outputText id="pharmacie" value="Pharmacie :" />
                            <p:selectOneMenu
                                value="#{patientManagerBean.newPatient.pharmacie}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="pharmacieConverter" />
                                <f:selectItems value="#{pharmacieManagerBean.pharmacieList}" />
                            </p:selectOneMenu>

                            <h:outputText id="laboratory" value="Laboratory :" />
                            <p:selectOneMenu
                                value="#{patientManagerBean.newPatient.laboratory}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="laboratoryConverter" />
                                <f:selectItems value="#{laboratoryManagerBean.laboratoryList}" />
                            </p:selectOneMenu>
                        </p:panelGrid>
                    </p:tab>
                    <p:tab title="Disponibility">
                        <p:panelGrid columns="2">
                            <h:outputText value="Monday" />
                            <p:selectOneRadio value="#{patientManagerBean.newPatient.monday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Tuesday" />
                            <p:selectOneRadio value="#{patientManagerBean.newPatient.tuesday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Wednesday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.newPatient.wednesday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Thursday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.newPatient.thursday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Friday" />
                            <p:selectOneRadio value="#{patientManagerBean.newPatient.friday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                        </p:panelGrid>
                    </p:tab>
                </p:tabView>
                <h:panelGrid columns="2"
                             style="margin-left: auto;margin-right: auto;">
                    <h:commandButton value="Ok" onclick="dlgAddPatient.hide();"
                                     action="createPatient" />
                    <h:commandButton value="Cancel" onclick="dlgAddPatient.hide();" />
                </h:panelGrid>
            </h:form>
        </p:dialog>

        <!-- Update Patient Modal -->
        <p:dialog id="modalUpdatePatient" header="Patient Information"
                  widgetVar="dlgUpdatePatient" modal="true">
            <h:form>
                <p:tabView orientation="left">
                    <p:tab title="Patient">
                        <p:panelGrid columns="2">
                            <h:outputText id="firstname" value="First name :" />
                            <p:inputText
                                value="#{patientManagerBean.selectedPatient.firstName}" />

                            <h:outputText id="lastname" value="Last name :" />
                            <p:inputText
                                value="#{patientManagerBean.selectedPatient.lastName}" />

                            <h:outputText id="birthday" value="Birthday :" />
                            <p:inputText
                                value="#{patientManagerBean.selectedPatient.birthday}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </p:inputText>

                            <h:outputText id="ssid" value="Ssid :" />
                            <p:inputText value="#{patientManagerBean.selectedPatient.ssid}" />

                            <h:outputText id="phone" value="Phone :" />
                            <p:inputText value="#{patientManagerBean.selectedPatient.phone}" />

                            <h:outputText id="address" value="Address :" />
                            <p:inputText value="#{patientManagerBean.selectedPatient.address}" />

                            <h:outputText id="priority" value="Priority :" />
                            <p:inputText
                                value="#{patientManagerBean.selectedPatient.priority}" />
                        </p:panelGrid>
                    </p:tab>
                    <p:tab title="Professional">
                        <p:panelGrid columns="2">
                            <h:outputText id="medecin" value="Medecin :" />
                            <p:selectOneMenu
                                value="#{patientManagerBean.selectedPatient.medecin}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="medecinConverter" />
                                <f:selectItems value="#{medecinManagerBean.medecinList}" />
                            </p:selectOneMenu>

                            <h:outputText id="pharmacie" value="Pharmacie :" />
                            <p:selectOneMenu
                                value="#{patientManagerBean.selectedPatient.pharmacie}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="pharmacieConverter" />
                                <f:selectItems value="#{pharmacieManagerBean.pharmacieList}" />
                            </p:selectOneMenu>

                            <h:outputText id="laboratory" value="Laboratory :" />
                            <p:selectOneMenu
                                value="#{patientManagerBean.selectedPatient.laboratory}">
                                <f:selectItem itemLabel="Select One" itemValue="" />
                                <f:converter converterId="laboratoryConverter" />
                                <f:selectItems value="#{laboratoryManagerBean.laboratoryList}" />
                            </p:selectOneMenu>
                        </p:panelGrid>
                    </p:tab>
                    <p:tab title="Disponibility">
                        <p:panelGrid columns="2">
                            <f:facet name="header">Disponibility</f:facet>
                            <h:outputText value="Monday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.selectedPatient.monday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Tuesday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.selectedPatient.tuesday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Wednesday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.selectedPatient.wednesday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Thursday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.selectedPatient.thursday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                            <h:outputText value="Friday" />
                            <p:selectOneRadio
                                value="#{patientManagerBean.selectedPatient.friday}">
                                <f:selectItem itemLabel="No" itemValue="-1" />
                                <f:selectItem itemLabel="From 8h" itemValue="0" />
                                <f:selectItem itemLabel="From 10h" itemValue="1" />
                                <f:selectItem itemLabel="From 14h" itemValue="2" />
                                <f:selectItem itemLabel="From 16h" itemValue="3" />
                            </p:selectOneRadio>
                        </p:panelGrid>
                    </p:tab>
                </p:tabView>
                <h:panelGrid columns="2"
                             style="margin-left: auto;margin-right: auto;">
                    <h:commandButton value="Ok" onclick="dlgUpdatePatient.hide();"
                                     action="updatePatient" />
                    <h:commandButton value="Cancel" onclick="dlgUpdatePatient.hide();" />
                </h:panelGrid>
            </h:form>
        </p:dialog>

        <!-- Patient Dalete Modal -->
        <p:dialog id="modalDeletePatient" header="Delete Patient"
                  widgetVar="dlgDeletePatient" modal="true">
            <h:form>
                <h:panelGrid columns="1">
                    <h:outputText value="Are you sure to delete this patient ?" />
                </h:panelGrid>
                <h:panelGrid columns="2"
                             style="margin-left: auto;margin-right: auto;">
                    <h:commandButton value="Delete" action="deletePatient"
                                     onclick="dlgDeletePatient.hide();" />
                    <h:commandButton value="Cancel" onclick="dlgDeletePatient.hide();" />
                </h:panelGrid>
            </h:form>
        </p:dialog>

    </h:body>
</html>